<template>
  <div>
   <el-form :model="todoValidateForm" ref="todoValidateForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="标题" prop="title"
    :rules="[
      { required: true, message: '标题不能为空'},
    ]"
  >
    <el-input type="title" v-model="todoValidateForm.title" autocomplete="off"></el-input>
  </el-form-item>

  <el-form-item label="内容" >
    <el-input type="textarea" v-model="todoValidateForm.content"></el-input>
  </el-form-item>

  <el-form-item > 
    <el-button type="primary" @click="submitForm('todoValidateForm')" >提交</el-button>
    <el-button @click="resetForm('todoValidateForm')">重置</el-button>
  </el-form-item>
</el-form>

  </div>
</template>

<script>
export default {
    data() {
      return {
        todoValidateForm: {
          title:'',
          content:''
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('提交成功!\ntitle:'+this.todoValidateForm.title + 'ncontent:' + this.todoValidateForm.content);
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>